<?php
// Awesome Facebook Application
// 
// Name: Fun signature
//

 
require_once 'facebook.php';
require_once 'config.php';
$strLangue = "fr";
if (isset($_POST["langue"])) $strLangue = $_POST["langue"];
if (isset($_GET["langue"])) $strLangue = $_GET["langue"];

if($strLangue =='en'){
    require_once('english.php');
}else{
    require_once('french.php');
}



function redirectLogin($f){
    #There's no active session, let's generate one
    $loginUrl = $f->getLoginUrl(
        array(
          #  'locale' => 'fr_FR',        
            'canvas'=>1,
            'fbconnect'=>0,
            'cancel_url'      => 'http://www.facebook.com/',
            'req_perms'=> 'user_photos,user_videos,friends_about_me,publish_stream,email',
            'display' => 'page',
            'next' => urlencode(FACEBOOK_CANVAS_URL)
              ));
    //header("Location: ".$loginUrl);
    echo "<script type='text/javascript'>\n top.location.href='".$loginUrl."';\n</script>";
//    return $loginUrl;
    exit;
}
//
//if(!isset($_COOKIE['fbsetting_'.APP_ID])){
//    echo "<script> alert('Turn on cookie to load properly');</script>";
//}
//
$facebook = new Facebook(array(
  'appId'  => APP_ID,
  'secret' => APP_SECRET,
  'cookie' => true
));
#checking that we have active session
$session = $facebook->getSession();
$user=''; $uid='';


if(!empty($session)){
    # Active session, let's try getting the user id(getUser())
    # and user info (api-> ('/me'))
    try{
//        #check if the user has granted access to posting in the wall
            $uid = $facebook->getUser();
            $user = $facebook->api('/me');
    }catch(Exception $e){
        redirectLogin($facebook);               
    }   
}else{
    redirectLogin($facebook);
}

?>